class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left = None
        self.right = None


def preorder(root):     # 前序
    if root:
        print(root.val, end='')
        preorder(root.left)
        preorder(root.right)


def inorder(root):
    if root:
        inorder(root.left)
        print(root.val, end=' ')
        inorder(root.right)


def postorder(root):
    if root:
        postorder(root.left)
        postorder(root.right)
        print(root.val, end=' ')


#       1
#      / \
#     2   3
#    / \
#   4   5


root = TreeNode(1)

root.left = TreeNode(2)
root.right = TreeNode(3)

root.left.left = TreeNode(4)
root.left.right = TreeNode(5)

root.right.left = TreeNode(6)
root.right.right = TreeNode(7)


print("前序遍历：")
preorder(root)


print("\n中序遍历：")
inorder(root)


print("\n后续遍历:")
postorder(root)


"""
    知识点      备注
    栈/队列     必备基础，手写
    链表翻转    频繁面试题，记住三个指针
    堆排序      必须熟悉堆化(heapify)
    二叉树遍历   递归套路要熟
"""